import useUserStore from "@/store/modules/user";

export default {
    mounted(el, binding, vnode) {
        const {value} = binding;
        const all_permission = "*";
        const permissions = useUserStore().permissions || [];

        if(value && value instanceof Array && value.length > 0){
            const permissionTags = value;
            const hasPermissions = permissions.some(item => {
                return all_permission === item || permissionTags.includes(item);
            })

            if(!hasPermissions){
                el.parentNode && el.parentNode.removeChild(el);
            }
        }else{
            throw new Error('请设置权限标识')
        }
    }
}
